//
//  ESTActivityHomeModel.m
//  ESTSCRMAPP
//
//  Created by 李贤立 on 2018/9/30.
//  Copyright © 2018年 Capfer. All rights reserved.
//

#import "ESTActivityHomeModel.h"
#import "ESTActivityModel.h"
#define NAME_CODE    @"DATAITEM_CODE"
#define VALUE_CODE   @"DATA_AMOUNT"
#define CN_CODE      @"DATAITEM_CN"
@implementation ESTActivityHomeModel
- (NSArray<NSString *> *)achieveValueArray {
    return @[
             self.BUS_FOLLOWUP,
             self.BUS_INTENT,
             self.BUS_NOLINK,
             self.BUS_FAIL,
             self.BUS_WECHART,
             self.BUS_PAY,
             self.BUS_ORDER,
             self.BUS_READYCOME,
             self.BUS_COME,
             self.BUS_NOTPAY_PLANCOME,
             self.BUS_REALCOME
             ];
}
- (NSArray<NSString *> *)matterValueArray {
    return @[
             self.PLAN_FOLLOWUP,
             self.PLAN_FOLLOWUP_AGIN,
             self.PLAN_WALKIN
             ];
}
- (NSArray *)reportValueArray {
    NSString *yy_percentage = @"-";
    if ([self.YY_TARGET floatValue] > 0) {
        yy_percentage = [NSString stringWithFormat:@"%.2f", [self.YY_REAL floatValue]/[self.YY_TARGET floatValue]];
    }
    NSString *cyj_percentage = @"-";
    if ([self.CYJ_TARGET floatValue] > 0) {
        cyj_percentage = [NSString stringWithFormat:@"%.2f", [self.CYJ_REAL floatValue]/[self.CYJ_TARGET floatValue]];
    }
    NSString *dd_percentage = @"-";
    if ([self.DD_TARGET floatValue] > 0) {
        dd_percentage = [NSString stringWithFormat:@"%.2f", [self.DD_REAL floatValue]/[self.DD_TARGET floatValue]];
    }
    return @[
             @[self.YY_REAL,
             self.YY_TARGET,
             yy_percentage],
             @[self.CYJ_REAL,
             self.CYJ_TARGET,
             cyj_percentage],
             @[self.DD_REAL,
             self.DD_TARGET,
             dd_percentage]
             ];
}
+ (void)requestActivityHomeDataWithActivityID:(NSString *)activityID startDate:(NSString *)startDate endDate:(NSString *)endDate success:(void(^)(ESTActivityHomeModel *model))success failure:(void(^)(NSString *error))failure {
    if (!activityID || !startDate || !endDate) return;
    NSDictionary *parameter = @{
                                @"START_DATE": startDate,
                                @"END_DATE": endDate,
                                @"ACTIVITY_ID": activityID
                                };
    [NetTool postWithCode:Code_Activity_Home parameter:parameter success:^(NSDictionary *result) {
        NSArray<NSDictionary *> *arr = [NSArray arrayWithArray:result[@"DATA_INFO"]];
        ESTActivityHomeModel *model = [[ESTActivityHomeModel alloc] init];
        for (NSDictionary *obj in arr) {
            if ([obj[NAME_CODE] isEqualToString:@"BUS_FOLLOWUP"]) {
                model.BUS_FOLLOWUP = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_WECHART"]) {
                model.BUS_WECHART = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_PAY"]) {
                model.BUS_PAY = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_ORDER"]) {
                model.BUS_ORDER = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_INTENT"]) {
                model.BUS_INTENT = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_PLANCOME"]) {
                model.BUS_PLANCOME = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_REALCOME"]) {
                model.BUS_REALCOME = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_NOLINK"]) {
                model.BUS_NOLINK = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_READYCOME"]) {
                model.BUS_READYCOME = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_COME"]) {
                model.BUS_COME = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_NOTPAY_PLANCOME"]) {
                model.BUS_NOTPAY_PLANCOME = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"BUS_FAIL"]) {
                model.BUS_FAIL = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"PLAN_FOLLOWUP"]) {
                model.PLAN_FOLLOWUP = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"PLAN_FOLLOWUP_AGIN"]) {
                model.PLAN_FOLLOWUP_AGIN = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"PLAN_WALKIN"]) {
                model.PLAN_WALKIN = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"PLAN_BUS_FAIL"]) {
                model.PLAN_BUS_FAIL = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"YY_REAL"]) {
                model.YY_REAL = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"YY_TARGET"]) {
                model.YY_TARGET = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"CYJ_REAL"]) {
                model.CYJ_REAL = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"CYJ_TARGET"]) {
                model.CYJ_TARGET = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"DD_REAL"]) {
                model.DD_REAL = obj[VALUE_CODE];
                continue;
            }
            if ([obj[NAME_CODE] isEqualToString:@"DD_TARGET"]) {
                model.DD_TARGET = obj[VALUE_CODE];
                continue;
            }
        }
        if (success) {
            success(model);
        }
    } failure:^(NSString *error) {
        if (failure) {
            failure(error);
        }
    }];
}
@end
